import * as tonge from './tonge.js';
import * as NotifactionCenter from './WxNotificationCenter.js';
//app.js
const token = wx.getStorageSync('CookieKey');
App({
  onLaunch: function () {

    // 静默登录
    // this.doLogin();
  },

  doLogin: function () {
    const self = this;
    if (token){
      tonge.doGet(`/userInfo/tokenprofile`, {
        'token': token
      }).then(res => {
        if (res.code == "200") {
          //检测是登录超时  顺便刷新数据
          self.globalData.isLogin = true;
          self.globalData.userInfo = res.data
        }
      }).catch(res => {
        //捕获超时
        if (res.code == 403225) {
          wx.showToast({
            title: '用户未登陆或登录超时,请登录',
            icon: 'none'
          })
          self.globalData.isLogin = false;
        }
      })
    }
  },

  globalData: {
    userInfo: {},     // 用户信息
    isLogin: false  // 是否登录
  }
})